package com.bfly.mall.report.controller;

import com.alibaba.fastjson.JSONObject;
import com.bfly.common.ResponseUtil;
import com.bfly.core.base.controller.BaseController;
import com.bfly.core.base.entity.ResponseData;
import com.bfly.core.security.PermissionCheck;
import com.bfly.mall.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 产品统计
 * @author 长沙商脉科技有限公司
 * @date 2020/10/16 20:46
 */
@RestController
@RequestMapping(value = "/manage/report/product")
public class ProductReportController extends BaseController {

    @Autowired
    private IProductService productService;

    /**
     * 商品综合统计
     *
     * @author 长沙商脉科技有限公司
     * @date 2020/6/4 11:35
     */
    @GetMapping(value = "/statistics")
    @PermissionCheck(required = false)
    public void statisticsProduct(HttpServletResponse response) {
        Map<String, Object> param = new HashMap<>();
        param.put("is_deleted", false);

        // 商品总数量
        long total = productService.getCount(param);

        // 上架产品
        param.put("is_on_shelf", true);
        long onShelf = productService.getCount(param);

        // 下架产品
        param.put("is_on_shelf", false);
        long offShelf = productService.getCount(param);

        // 活动产品
        param.remove("status");
        param.put("promote", true);
        long promote = 0;//productService.getCount(param);

        JSONObject json = new JSONObject();
        json.put("total", total);
        json.put("onShelf", onShelf);
        json.put("offShelf", offShelf);
        json.put("promote", promote);
        ResponseUtil.writeJson(response, ResponseData.getSuccess(json));
    }
}
